import '../../css/addNote.css'
import ajax from '../../utils/ajax';
const form = document.forms.add;
form.onsubmit = form_submit;


function form_submit(e) {
    e.preventDefault()
    if (!form.title.value || !form.content.value) {
        alert('标题或者内容不能为空');
        return;
    }

    ajax('post', '/api/addNote', {
        title: form.title.value,
        content: form.content.value,
    }).then(result => {
        if (result.flag) {
            alert(result.msg)
            if (confirm('您确定继续发布吗？')) {
                form.reset();
            } else {
                location.assign('/index.html');
            }
        }
    }
    )
}